﻿// Copyright (c) Inossem. All rights reserved.
// Licensed under the LGPL-3.0 license. See LICENSE file in the project root for full license information.
using DWF.Studio.RemoteCtrls.SnippetExplorer;
using DWF.Studio.Share.Log;
using System;
using System.Activities.Presentation;
using System.Activities.Presentation.Services;
using System.AddIn.Contract;
using System.AddIn.Pipeline;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace DWF.Studio.RemoteCtrls.Proxy
{
    public class SnippetExplorerProxy : MarshalByRefProxyBase
    {
        /// <summary>
        /// 片段模型改变
        /// </summary>
        public Action<ShowSnippetEventArgs> SnippetShow = null;
        public Action<RepairSnippetEventArgs> RepairSnippetActivity = null;
        public Action<EventArgs> CheckSnippetActivity = null;
        public Action<SnippetCoverEventArgs> IsCoverSnippet = null;

        UCtrlSnippetExplorer wfSnippetExplorer = null;
        public SnippetExplorerProxy()
        {
            wfSnippetExplorer = new UCtrlSnippetExplorer();
        }

        /// <summary>
        /// 获取片段
        /// </summary>
        /// <param name="snippetAssemblies"></param>
        /// <returns></returns>
        public INativeHandleContract GetSnippetExplorer()
        {
            wfSnippetExplorer.SnippetShow += (e) => { SnippetShow?.Invoke(new ShowSnippetEventArgs(e.SnippetName)); };
            wfSnippetExplorer.RepairSnippetActivity += (e) => { RepairSnippetActivity?.Invoke(new RepairSnippetEventArgs(e.SnippetName)); };
            wfSnippetExplorer.CheckSnippetActivity += (e) => { CheckSnippetActivity?.Invoke(EventArgs.Empty); };
            wfSnippetExplorer.IsCoverSnippet += (e) => { IsCoverSnippet?.Invoke(new SnippetCoverEventArgs(e.SnippetName,e.FullName,e.TargetFolder)); };

            return FrameworkElementAdapters.ViewToContractAdapter(wfSnippetExplorer);
        }
        public void Reload()
        {
            wfSnippetExplorer.Reload();
        }
        public void CoverSnippet(string fullName, string targetFolder)
        {
            wfSnippetExplorer.AddFavorite(fullName,targetFolder);
        }
    }
}
